﻿
@{
    Layout = "_layout";
}
@{
    ViewData["Title"] = "用户列表";
    var UAdd = ViewBag.Uadd as List<BuyWithoutLoseMoney.Core.Models.UserAddress>;
    var UType = ViewBag.Utype as List<BuyWithoutLoseMoney.Core.Models.UserType>;
}
<div>
    <div class="demoTable layui-form">
        搜索用户名： @*根据用户昵称进行查询*@
        <div class="layui-inline">
            <input class="layui-input" name="Name" id="Name" autocomplete="off">
        </div>
        <div class="layui-inline">
            <button class="layui-btn" data-type="reload">搜索</button>
        </div>
    </div>
</div>
<table class="layui-hide" id="demo" lay-filter="test"></table>
@section Scripts{
    <script>
        layui.use('table', function () {
            var table = layui.table;
            //第一个实例
            table.render({
                elem: '#demo'
                , url: '/admin/User/index' //数据接口
                , page: true //开启分页
                , method: "post"
                , cols: [[ //表头
                    { field: 'id', title: 'ID', width: 100, sort: true, fixed: 'left' }
                    , { field: 'nickName', title: '昵称', width: 120 }
                    , { field: 'gender', title: '性别', width: 100, sort: true }
                    , { field: 'phone', title: '手机号', width: 120 }
                    , { field: 'email', title: '邮箱', width: 140 }
                    , { field: 'createtime', title: '创建时间', width: 140, sort: true }
                    , { field: 'updatetime', title: '更新时间', width: 140, sort: true }
                    , { field: 'username', title: '用户名', width: 100 }
                           @*用户密码不显示*@
                    , { field: 'iszhuxiao', title: '是否注销', width: 120 }
                         @*写两个链接点击查看地址和类型*@
                     ]]
                , id: "UserList"
                ,done:function(){
                    $("[data-field='gender']").children().each(function(){
                        if($(this).text()=="1"){
                            $(this).text("男");
                        }else if($(this).text()=="2"){
                            $(this).text("女");
                        } else if ($(this).text() == "3") {
                            $(this).text("保密");
                        }
                    });
                    $("[data-field='iszhuxiao']").children().each(function (){
                        if ($(this).text() == "true") {
                            $(this).text("已注销");
                        } else if ($(this).text() == "false") {
                            $(this).text("未注销");
                        }
                    });
                }
            });
            //搜索功能
            var $ = layui.$, active = {
                reload: function () {
                    var Name = $('#Name');
                    //执行重载
                    table.reload('UserList', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            Name: Name.val(),  
                        }
                    });
                }
            };
            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            });
    </script>
}